﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using PSTaskDialog;

namespace ArduinoSketch.Core
{
    public partial class frmNewSketch : Form
    {
        private SolutionEntity _solution;

        public frmNewSketch()
        {
            InitializeComponent();
            this._solution = new SolutionEntity();
            this.CreateProfile();
        }

        /// <summary>
        /// 
        /// </summary>
        private void CreateProfile()
        {
            Hardwares _hardware = Utils.LoadHardwardBoard();

            foreach (var profile in _hardware.Profile)
            {
                this.cmbProfile.Items.Add(profile);
            }

            this.cmbProfile.SelectedIndex = -1;
        }

        /// <summary>
        /// 
        /// </summary>
        public SolutionEntity Solution
        {
            get { return _solution; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string HardwareProfile { get; set; }

        private void btnCreate_Click(object sender, EventArgs e)
        {
       
            if (String.IsNullOrEmpty(this.txtSketchName.Text))
            {
                PSTaskDialog.cTaskDialog.MessageBox(
                                    "Warning",
                                    "Create sketch",
                                    "Sketch name is not emtry!",
                                    eTaskDialogButtons.OK,
                                    eSysIcons.Warning);
                return;
            }

            if (String.IsNullOrEmpty(this.txtLocation.Text))
            {
                PSTaskDialog.cTaskDialog.MessageBox(
                                    "Warning",
                                    "Create sketch",
                                    "Sketch location is not emtry!",
                                    eTaskDialogButtons.OK,
                                    eSysIcons.Warning);
                return;
            }

            if (String.IsNullOrEmpty(this.cmbProfile.Text))
            {
                PSTaskDialog.cTaskDialog.MessageBox(
                                    "Warning",
                                    "Create sketch",
                                    "Hardware Profile is not emtry!",
                                    eTaskDialogButtons.OK,
                                    eSysIcons.Warning);
                return;
            }

            _solution = new SolutionEntity();
            this.HardwareProfile = this.cmbProfile.Text;
            _solution.SolutionName = this.txtSketchName.Text;
            _solution.SolutionPath = string.Format(@"{0}\{1}", txtLocation.Text, _solution.SolutionName);

            this.DialogResult = DialogResult.OK;
        }

        private void btnLocation_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                this.txtLocation.Text = folderBrowserDialog.SelectedPath;
            }
        }
    }
}
